<?php
// Start the clock for the page parse time log
  define('PAGE_PARSE_START_TIME', microtime());

// Set the level of error reporting
  error_reporting(E_ALL & ~E_NOTICE);

// Check if register_globals is enabled.
// Since this is a temporary measure this message is hardcoded. The requirement will be removed before 2.2 is finalized.
// da fix code trong include - admin
/*
  if (function_exists('ini_get')) {
    ini_get('register_globals') or exit('FATAL ERROR: register_globals is disabled in php.ini, please enable it!');
  }
*/

// Set the local configuration parameters - mainly for developers
//  if (file_exists('includes/local/configure.php')) include('includes/local/configure.php');

// Include application configuration parameters
//  require('includes/configure.php');

$path_configure_file = "../../library/php/includes/configure.php";
if (file_exists($path_configure_file)) 
{
	require('../../library/php/includes/configure.php'); 
	$path_include = DIR_WS_INCLUDES_ADMIN;
	$path_function = DIR_WS_FUNCTIONS_ADMIN;
	$path_classes = DIR_WS_CLASSES_ADMIN;
	$path_languages = DIR_WS_LANGUAGES_ADMIN;
	/*
	echo "path_include: $path_include <br>";
	echo "path_function: $path_function<br>";
	echo "path_classes: $path_classes<br>";
	echo "path_languages: $path_languages<br>";
	*/
}
else {
	require('../library/php/includes/configure.php');
	$path_include = DIR_WS_INCLUDES;
	$path_function = DIR_WS_FUNCTIONS;
	$path_classes = DIR_WS_CLASSES;
	$path_languages = DIR_WS_LANGUAGES;
	/*
	echo "path_include: $path_include <br>";
	echo "path_function: $path_function<br>";
	echo "path_classes: $path_classes<br>";
	echo "path_languages: $path_languages<br>";	
	*/
}



// Define the project version
  define('PROJECT_VERSION', 'Webdong version 1.0');

// set php_self in the local scope
  $PHP_SELF = (isset($HTTP_SERVER_VARS['PHP_SELF']) ? $HTTP_SERVER_VARS['PHP_SELF'] : $HTTP_SERVER_VARS['SCRIPT_NAME']);

// Used in the "Backup Manager" to compress backups
  define('LOCAL_EXE_GZIP', '/usr/bin/gzip');
  define('LOCAL_EXE_GUNZIP', '/usr/bin/gunzip');
  define('LOCAL_EXE_ZIP', '/usr/local/bin/zip');
  define('LOCAL_EXE_UNZIP', '/usr/local/bin/unzip');

// include the list of project filenames
require($path_include . 'filenames.php'); 

  

// include the list of project database tables
  require($path_include . 'database_tables.php');

// customization for the design layout
  define('BOX_WIDTH', 125); // how wide the boxes should be in pixels (default: 125)

// Define how do we update currency exchange rates
// Possible values are 'oanda' 'xe' or ''
  define('CURRENCY_SERVER_PRIMARY', 'oanda');
  define('CURRENCY_SERVER_BACKUP', 'xe');

// include the database functions
  require($path_function . 'database.php');

// make a connection to the database... now
  tep_db_connect() or die('Unable to connect to database server!');



// define our general functions used application-wide
//tam thoi tat
  require($path_function . 'general.php');
  require($path_function . 'html_output.php');


// some code to solve compatibility issues
  require($path_function . 'compatibility.php');

// check to see if php implemented session management functions - if not, include php3/php4 compatible session class
  if (!function_exists('session_start')) {
    define('PHP_SESSION_NAME', 'myCAdminID');
    define('PHP_SESSION_PATH', '/');
    define('PHP_SESSION_SAVE_PATH', SESSION_WRITE_DIRECTORY);

    include($path_classes . 'sessions.php');
  }

// define how the session functions will be used
  require($path_function . 'sessions.php');

// set the session name and save path
  tep_session_name('myID');
  tep_session_save_path(SESSION_WRITE_DIRECTORY);

// set the session cookie parameters
   if (function_exists('session_set_cookie_params')) {
    session_set_cookie_params(0, DIR_WS_ADMIN);
  } elseif (function_exists('ini_set')) {
    ini_set('session.cookie_lifetime', '0');
    ini_set('session.cookie_path', DIR_WS_ADMIN);
  }

// lets start our session
  tep_session_start();

// set the language
  if (!tep_session_is_registered('language') || isset($HTTP_GET_VARS['language'])) {
    if (!tep_session_is_registered('language')) {
      tep_session_register('language');
      tep_session_register('languages_id');
    }

    include($path_classes . 'language.php');
    $lng = new language();

    if (isset($HTTP_GET_VARS['language']) && tep_not_null($HTTP_GET_VARS['language'])) {
      $lng->set_language($HTTP_GET_VARS['language']);
    } else {
      $lng->get_browser_language();
    }

    $language = $lng->language['directory'];
    $languages_id = $lng->language['id'];
  }

// include the language translations
$language = "english";
  require($path_languages . $language . '.php');
  $current_page = basename($PHP_SELF);
  if (file_exists($path_languages . $language . '/' . $current_page)) {
    include($path_languages . $language . '/' . $current_page);
  }



// setup our boxes
  require($path_classes . 'table_block.php');
  require($path_classes . 'box.php');

// initialize the message stack for output messages
  require($path_classes . 'message_stack.php');
  $messageStack = new messageStack;


// entry/item info classes
  require($path_classes . 'object_info.php');

// email classes
  require($path_classes . 'mime.php');
  require($path_classes . 'email.php');

// file uploading class
  require($path_classes . 'upload.php');

// calculate category path
  if (isset($HTTP_GET_VARS['cPath'])) {
    $cPath = $HTTP_GET_VARS['cPath'];
  } else {
    $cPath = '';
  }

  if (tep_not_null($cPath)) {
    $cPath_array = tep_parse_category_path($cPath);
    $cPath = implode('_', $cPath_array);
    $current_category_id = $cPath_array[(sizeof($cPath_array)-1)];
  } else {
    $current_category_id = 0;
  }

// default open navigation box
  if (!tep_session_is_registered('selected_box')) {
    tep_session_register('selected_box');
    $selected_box = 'configuration';
  }

  if (isset($HTTP_GET_VARS['selected_box'])) {
    $selected_box = $HTTP_GET_VARS['selected_box'];
  }

// the following cache blocks are used in the Tools->Cache section
// ('language' in the filename is automatically replaced by available languages)
  $cache_blocks = array(array('title' => TEXT_CACHE_CATEGORIES, 'code' => 'categories', 'file' => 'categories_box-language.cache', 'multiple' => true),
                        array('title' => TEXT_CACHE_MANUFACTURERS, 'code' => 'manufacturers', 'file' => 'manufacturers_box-language.cache', 'multiple' => true),
                        array('title' => TEXT_CACHE_ALSO_PURCHASED, 'code' => 'also_purchased', 'file' => 'also_purchased-language.cache', 'multiple' => true)
                       );

// check if a default currency is set
  if (!defined('DEFAULT_CURRENCY')) {
    $messageStack->add(ERROR_NO_DEFAULT_CURRENCY_DEFINED, 'error');
  }

// check if a default language is set
  if (!defined('DEFAULT_LANGUAGE')) {
    $messageStack->add(ERROR_NO_DEFAULT_LANGUAGE_DEFINED, 'error');
  }

  if (function_exists('ini_get') && ((bool)ini_get('file_uploads') == false) ) {
    $messageStack->add(WARNING_FILE_UPLOADS_DISABLED, 'warning');
  }
?>
